package com.lexin.engine.hive.udf;

import org.apache.hadoop.hive.ql.exec.UDF;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: letu
 * @description:
 * @author: XL.Gao
 * @create: 2021-01-18 09:19
 **/
public class TMGZHiveUDF extends UDF {

    private static Map<String, String> map = new HashMap<>();

    private static Map<String, String> map1 = new HashMap<>();

    static {
        synchronized (map){
            if(map == null || map.size() == 0){
                map.put("Q", "0");
                map.put("W", "1");
                map.put("E", "2");
                map.put("R", "3");
                map.put("T", "4");
                map.put("Y", "5");
                map.put("U", "6");
                map.put("H", "7");
                map.put("K", "8");
                map.put("P", "9");

                map1.put("0", "Q");
                map1.put("1", "W");
                map1.put("2", "E");
                map1.put("3", "R");
                map1.put("4", "T");
                map1.put("5", "Y");
                map1.put("6", "U");
                map1.put("7", "H");
                map1.put("8", "K");
                map1.put("9", "P");
            }
        }
    }

    public String evaluate(){

        StringBuffer sb = new StringBuffer();
        sb.append("****************************************************"+System.getProperty("line.separator"));
        sb.append("脱敏规则："+System.getProperty("line.separator"));
        sb.append(map1.toString()+System.getProperty("line.separator"));
        sb.append("解敏规则："+System.getProperty("line.separator"));
        sb.append(map.toString()+System.getProperty("line.separator"));
        sb.append("****************************************************"+System.getProperty("line.separator"));

        return sb.toString();
    }

    public String role(){

        return map.toString();
    }

    public static void main(String args[]){

        TMGZHiveUDF jmHiveUDF = new TMGZHiveUDF();
        String tfString = jmHiveUDF.evaluate();
        System.out.println(tfString);
        System.out.println(jmHiveUDF.role());
    }
}
